#!/usr/bin/perl
use strict;
use warnings;
use autodie;
use Getopt::Std;

my %opts =('n', "RESULTS");
getopts(':n:h', \%opts);

print "<div>\n";

my $dir_sub;
if ("$opts{n}" eq "cnv") {
	print "<h1>CNV</h1>\n";
	$dir_sub=".cnvsc";
}elsif ("$opts{n}" eq "snp") {
	print "<h1>SNP</h1>\n";
	$dir_sub="snp"
}elsif ("$opts{n}" eq "tes") {
	print "<h1>TEST</h1>\n";
	$dir_sub=".tes"
}elsif ("$opts{n}" eq "info") {
	print "<h1>INFO</h1>\n";
	$dir_sub=".info"
}elsif ("$opts{n}" eq "test") {
	print "<h1>TEST</h1>\n";
	$dir_sub=".test"
}else {
	print "<h1>" . uc($opts{n}) . "</h1>\n";
	$dir_sub=".$opts{n}"
}
	

my $blank="&nbsp";
my $blank = $blank x 4;
# my $dot = "&#007";

print "<ol>\n";
while (<>) {
	chomp;
	my @item=split /\t/, $_;
	my $time=`date -d \@$item[1] '+%b-%d-%Y %H:%M'`;
	chomp $time;
	# print "<p><a href=\"$item[0]\" target=\"_blank\">$item[0]</a>$blank-$blank<i>$time</i></p>\n";
	
	# print "<li class=\"toggle_sub_list\"><a href=\"" . $item[0] . " target=\"_blank\">" . $item[0] . "</a>$blank-$blank<i>$time</i></li>\n";
	print "<li class=\"toggle_sub_list\">$item[0]$blank-$blank<i>$time</i></li>\n";
	
	opendir DIR ,$item[0] || die "cant open $!";
	print "<ul class=\"sub_list\">\n";
	foreach my $file (readdir DIR) {
		if ($file =~ /^[^\.]/) {
		print '<li><a target="_blank" href="http://192.168.10.113:8000/' . "$dir_sub/" . "$item[0]" . '/' . "$file" . '">' . "$file" . '</a></li>' . "\n";
		}
	}
	print "</ul>\n";
	closedir DIR;

	
}
print "</ol>\n";
print "</div>\n";